<template>
	<view class="padding flex flex-direction">
		<button class="cu-btn bg-mauve margin-tb-sm lg" @click="toPay">立即支付</button>
	</view>
</template>

<script>
import {order} from '@/config/mixins.js'
	export default {
		mixins:[order],
		props: {
			orderId: {
				type: String,
				default () {
					return ''
				}
			}
		},
		data() {
			return {}
		},
		methods: {
			toPay() {
				let _this = this
				this.$api.order_pay({
					order_id: this.orderId
				}).then(res => {
					if (res.code) {
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: res.data.signType,
							paySign: res.data.paySign,
							success: function(e) {
								if (e.errMsg === 'requestPayment:ok') {
									_this.$common.successToShow(res.msg, () => {
										_this.getOrderDetail('pay');
									})
								}
							},
							fail: function(err) {
								_this.$common.errorToShow('fail:' + JSON.stringify(err));
							}
						});
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			}			
		}

	}
</script>

<style>

</style>
